package reflect;

import io.Person;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

public class ReflectDemo3 {
    public static void main(String[] args) throws InvocationTargetException, InstantiationException, IllegalAccessException, NoSuchMethodException, ClassNotFoundException {

        Class cls = Class.forName("reflect.Person");
        Constructor constructor = cls.getConstructor(String.class);
        Object obj = constructor.newInstance("李四");
        System.out.println(obj);

         Constructor c2 = cls.getConstructor(String.class, int.class);
         Object obj2 = c2.newInstance("王五", 20);
         System.out.println(obj2);
    }
}
